/**
 * Created by fanghonghui on 2017/7/17.
 */
$(function(){
    var $loginBox = $("#loginBox"),
        $userInfo = $("#userInfo"),
        $registerBox = $("#registerBox");
    $registerBox.find('button').on('click',function(){
        $.ajax({
            type:'post',
            url:'/api/user/register',
            data:{
                username:$registerBox.find('[name="username"]').val(),
                password:$registerBox.find('[name="password"]').val(),
                repassword:$registerBox.find('[name="repassword"]').val()
            },
            dataType:'json',
            success:function(data){
                $registerBox.find('.colWarning').html(data.message);
            }
        })
    });
    $loginBox.find('button').on('click',function(){
        $.ajax({
            type:'post',
            url:'/api/user/login',
            data:{
                username:$loginBox.find('[name="username"]').val(),
                password:$loginBox.find('[name="password"]').val()
            },
            dataType:'json',
            success:function(data){
               window.location = location;
            }
        })
    })

    $("#logout").on('click',function(){
        $.ajax({
            url:'/api/user/logout',
            success:function(data){
                if(!data.code){
                    window.location=location;
                }
            }
        })
    })
})